<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:v="http://shale.apache.org/validator">

<f:view>
<f:loadBundle var="text" basename="#{torrentList.bundleName}"/>
    <head>
        <title>#{text['torrentList.title']}</title>
        <meta name="heading" content="#{text['torrentList.heading']}"/>
        <meta name="menu" content="TorrentMenu"/>
    </head>
<body id="torrentList">
<h:form id="addTorrent" enctype="multipart/form-data" onsubmit="return validateUploadForm(this)">
	<t:inputFileUpload id="file" value="#{torrentFileUpload.file}" storage="file" required="true" styleClass="file large">
        <v:commonsValidator client="true" type="required" arg="#{text['uploadForm.file']}"/>
    </t:inputFileUpload>
    <br/>
    <h:panelGroup styleClass="buttonBar bottom">
        <h:commandButton value="#{text['button.upload']}" action="#{torrentFileUpload.upload}"
            id="upload" styleClass="button"/>
        <h:commandButton value="#{text['button.cancel']}" action="mainMenu" immediate="true"
            id="cancel" styleClass="button" onclick="bCancel=true"/>
    </h:panelGroup>
</h:form>
<h:form id="editTorrent">

<h:commandButton value="#{text['button.add']}" action="add" id="add" immediate="true" styleClass="button"/>
<h:commandButton value="#{text['button.delete']}" action="delete" id="delete" immediate="true" styleClass="button" style="margin-left: 5px"/>

<c:set var="width" value="90%" />
<c:if test="#{torrentList.admin}">
	<c:set var="width" value="60%" />
</c:if>


<t:dataTable id="torrents" var="torrent" style="margin-top: 10px"
    value="#{torrentList.torrents}" rows="25" sortColumn="#{torrentList.sortColumn}"
    sortAscending="#{torrentList.ascending}" styleClass="scrollerTable table"
    headerClass="standardTable_Header" rowClasses="standardTable_Row1,standardTable_Row2"
    columnClasses="standardTable_Column,standardTable_Column,standardTable_Column,standardTable_Column,standardTable_ColumnCentered">

    <t:column width="10%">
        <f:facet name="header">
            <!--<t:commandSortHeader >-->
                <!--<h:selectBooleanCheckbox disabled="true"/>-->
            <!--</t:commandSortHeader>-->
        </f:facet>
        <h:selectBooleanCheckbox disabled="false"/>
    </t:column>

    <t:column width="#{width}">
        <f:facet name="header"> 
            <t:commandSortHeader columnName="id" arrow="true">
                    <!--<f:facet name="ascending">-->
                        <!--<t:graphicImage value="/images/arrow_up.png" rendered="true"-->
                            <!--style="position: relative; left: -7px" alt="Sort Ascending"/>-->
                    <!--</f:facet>-->
                    <!--<f:facet name="descending">-->
                        <!--<t:graphicImage value="/images/arrow_down.png" rendered="true"-->
                            <!--style="position: relative; left: -7px" alt="Sort Descending"/>-->
                    <!--</f:facet>-->


                <h:outputText value="#{text['torrent.id']}" />
                <!--<t:graphicImage value="/images/arrow_off.png" rendered="true"-->
                        <!--style="padding-left: 5px;" alt="Not Sorted"/>-->
            </t:commandSortHeader>
        </f:facet>
        <!--<h:commandLink action="#{torrentForm.edit}" value="#{torrent.id}">
            <f:param name="id" value="#{torrent.id}"/>
            <f:param name="from" value="list"/>
        </h:commandLink>-->
        <h:outputText value="#{torrent.fileName}" />
    </t:column>
    <c:if test="#{torrentList.admin}">
    <t:column width="30%">
        <f:facet name="header">
            <t:commandSortHeader columnName="owner" arrow="true">
                <h:outputText value="#{text['torrent.owner']}" />
            </t:commandSortHeader>
        </f:facet>
         <h:outputText value="#{torrent.owner.username}" />
    </t:column>
    </c:if>
</t:dataTable>

<ui:include src="/common/tableFooter.xhtml">
    <ui:param name="tableName" value="torrents"/>
</ui:include>


</h:form>
</body>
<v:validatorScript functionName="validateUploadForm"/>

<script type="text/javascript">
    Form.focusFirstElement($('addTorrent'));
    highlightFormElements();
</script>
</f:view>
</html>